package Selection;

import java.util.Arrays;
import java.util.concurrent.Callable;

public class Selection2 {
    public static void sort(Comparable[] a) {
        int len = a.length;
        for (int i = 0; i < len - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < len; j++) {
                if (greater(a[minIndex], a[j])) {
                    minIndex = j;
                }
            }
            exch(a, minIndex, i);
        }
    }

    public static void main(String[] args) {
        Integer[] arr = {6, 4, 5, 3, 1, 2};
        Selection2.sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static boolean greater(Comparable a, Comparable b) {
        return a.compareTo(b) > 0;
    }

    public static void exch(Comparable[] a, int i, int j) {
        Comparable temp;
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}